
             
/**
 * 
 *
 * @File name:  QueryTFixedAssetsByPagerAction.java 
 * @Create on:  2011-10-30 20:01:343
 * @Author   :  陈伟
 *
 * @ChangeList
 * ---------------------------------------------------
 * Date         Editor              ChangeReasons
 *
 */
           
        
package com.boho.estates.report.action;

            
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

import com.boho.base.dao.DaoHelper;
import com.boho.common.Constant;
import com.boho.common.ContentTypeUtils;
import com.boho.common.IoUtil;
import com.boho.estates.po.*;
import cn.boho.framework.actions.ActionImp;
import cn.boho.framework.context.ActionContext;
import cn.boho.framework.po.POUtils;
import cn.boho.framework.service.FileServerService;
import cn.boho.framework.service.MessageService;
import cn.boho.framework.exception.UserOperationException;
import cn.boho.framework.utils.DateUtils;
import cn.boho.framework.po.DynaBeanMap;
import cn.boho.framework.po.ComboPager;
import cn.boho.framework.po.Pager;
            
        
import com.boho.estates.report.dao.TFixedAssetsDao;
import com.boho.estates.report.service.TFixedAssetsService;

public class QueryTFixedAssetsByPagerAction extends ActionImp {
	private Connection con=null;
	private Pager pager=null;
	private int pageSize = 100;
	private int currentPage = 1;
	@Override
	protected void doException(ActionContext atx, Exception ex) {
		atx.setErrorContext("FSTI_COMMON_1004", MessageService.getMessage("FSTI_COMMON_1004"),"【资产基本信息】" ,ex);
	}
	@Override
	protected int performExecute(ActionContext atx) throws Exception {
		String isExport = atx.getStringValue("IS_EXPORT");
		String is_year = atx.getStringValue("IS_YEAR");
		String is_mon = atx.getStringValue("IS_MON");
		String fixedAssetsName =  atx.getStringValue("FIXED_ASSETS_NAME");
		String fixedAssetsType =  atx.getStringValue("FIXED_ASSETS_TYPE");
		String fixedAssetsNature =  atx.getStringValue("FIXED_ASSETS_NATURE");
		
		String dateFmt = "yyyy-MM-dd";
		String  CREATE_DATE_BEGIN = atx.getStringValue("CREATE_DATE_BEGIN");
		String CREATE_DATE_END = atx.getStringValue("CREATE_DATE_END");
		if(null!=atx.getStringValue("CREATE_DATE_BEGIN") && (atx.getStringValue("CREATE_DATE_BEGIN")).length()==7){
			dateFmt = "yyyy-MM";
		}else if(null!=atx.getStringValue("CREATE_DATE_BEGIN") && (atx.getStringValue("CREATE_DATE_BEGIN")).length()==4){
			dateFmt = "yyyy";
		}
		
		String createDateBegin = atx.getStringValue("CREATE_DATE_BEGIN");
		String createDateEnd = atx.getStringValue("CREATE_DATE_END");
		String createBy =  atx.getStringValue("CREATE_BY");
		Integer isValid =  atx.getIntegerValue("IS_VALID");
		pager = new Pager(pageSize, currentPage);
		String departIds  = (String)atx.getSessionValue(Constant.SESSION_DEPART_ARRAY);
		if(!("1").equals(isExport)){
			ComboPager cp=TFixedAssetsDao.queryTFixedAssetsByPager(con,pager,fixedAssetsName,fixedAssetsType,
					fixedAssetsNature,createDateBegin,createDateEnd,createBy,isValid,
					is_year,is_mon,CREATE_DATE_BEGIN,dateFmt,departIds);
					DaoHelper.setTpersonField(con, cp, "", "WITH_MANANGER");
					DaoHelper.setTsuppliersField(con, cp, "", "SUPPLIERS_NO");
			atx.setValue("T_FIXED_ASSETS", cp);
			
		}else{
			//TFixedAssetsService service = new TFixedAssetsService();
			String sResult = TFixedAssetsService.exportEXCEL(atx, con, pager, fixedAssetsName, fixedAssetsType, fixedAssetsNature, createDateBegin, createDateEnd, createBy, isValid,
					is_year,is_mon,CREATE_DATE_BEGIN,dateFmt, departIds);
			atx.setValue("T_FIXED_ASSETS", sResult);
		}
		return 1;

	}
	@Override
	protected int verifyParameters(ActionContext atx) throws Exception {
		con = atx.getConection();
		if(atx.getStringValue("PAGE_SIZE")!=null&&!atx.getStringValue("PAGE_SIZE").equals("")){
			pageSize = new Integer(atx.getStringValue("PAGE_SIZE"));
		}
		if(atx.getStringValue("CURRENT_PAGE")!=null&&!atx.getStringValue("CURRENT_PAGE").equals("")){
			currentPage = new Integer(atx.getStringValue("CURRENT_PAGE"));
		}
		return 1;
	}
	
	
	public void download(ActionContext atx,String filename){/*
		HttpServletRequest request = (HttpServletRequest)atx.getHttpRequest();

		String path=FileServerService.sfinalfile;//取得当前目录的路径
		path = path.replace("\\", "/");
		
		String fileNamein = filename;
		File  file=new File(fileNamein);
		HttpServletResponse response = atx.getHttpResponse();
		if(file!=null){
			String fileName=file.getName();
			InputStream inStream = null;
			try {
				int pos = fileName.lastIndexOf(".");
				String fileType= fileName.substring(pos + 1, fileName.length());
				String contentType=ContentTypeUtils.getContentType(fileType);
				response.setContentType(contentType);
				inStream = new FileInputStream(file);
				response.setContentType(contentType);
				byte[] b = new byte[1024 * 100];
				int len=0;
				while ((len = inStream.read(b)) > 0) {
					response.getOutputStream().write(b, 0, len);
				}
			} catch (IOException e) {
				e.printStackTrace();
			} finally {
				IoUtil.close(inStream);
				if (file.exists()) {
					file.delete();
				}
			}
		}else{
			
		}
		//return NONE;
	*/}
	
	
}
